#include "sockAddrIn.hpp"

SockAddrIn::SockAddrIn(const char* ip,
                       unsigned short port,
                       int family) {
    addr.sin_family = family;
    addr.sin_port = htons(port);
    inet_pton(family, ip, &addr.sin_addr.s_addr);
}
SockAddrIn::SockAddrIn() {
    addr.sin_family = AF_INET;
    addr.sin_port = 0;
    addr.sin_addr.s_addr = INADDR_ANY;
}
SockAddrIn::~SockAddrIn() {}

std::string SockAddrIn::getIp() {
    char ip[16]{0};
    inet_ntop(addr.sin_family, &addr.sin_addr.s_addr, ip, sizeof(ip));
    return ip;
}